<template>
  <!-- 头部公共组件 -->
  <div class="Tophead">
    <span>{{ sendTime }} &nbsp;&nbsp;&nbsp;&nbsp;</span>  
  </div>
</template>

<script>
export default {
  name: "Tophead",
  data() {
    return {
      sendTime: "", //当前时间
      newUser: "",
    };
  }, // props: ["name"],
  components: {},
  mounted() {

    this.format();
    setInterval(() => {
      this.format();
    }, 1000);
  },
  methods: {
    
    format() {
      const nowDate = new Date();
      const date = {
        year: nowDate.getFullYear(), //年
        month: nowDate.getMonth() + 1, //月
        date: nowDate.getDate(), //日
        when: nowDate.getHours(), //时
        points: nowDate.getMinutes(), //分
        seconds: nowDate.getSeconds(), //秒
      };
      const newmonth = date.month > 9 ? date.month : "0" + date.month; //月
      const day = date.date > 9 ? date.date : "0" + date.date; //日
      const when = date.when > 9 ? date.when : "0" + date.when; //时
      const points = date.points > 9 ? date.points : "0" + date.points; //分
      const seconds = date.seconds > 9 ? date.seconds : "0" + date.seconds; //秒
      this.sendTime =
        date.year +
        "年" +
        newmonth +
        "月" +
        day +
        "日" +
        when +
        ":" +
        points +
        ":" +
        seconds;
    }, //获取当前时间
  },
};
</script>
<style scoped>
.Tophead {
  position: relative;
  display: inline-block;
}
span {

  display: inline-block;

  /* top: 0px; */

 
}
</style>